package com.flx.dis.sharding.controller;

import com.flx.common.utils.result.ResultResponse;
import com.flx.dis.sharding.entity.Student;
import com.flx.dis.sharding.entity.User;
import com.flx.dis.sharding.service.StudentService;
import com.flx.dis.sharding.service.UserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Fenglixiong
 * @Date: 2021/6/9 17:54
 * @Description: student用来做水平分库分表测试
 */
@Slf4j
@Api
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/add")
    public ResultResponse add(@RequestBody Student student){
        try {
            Long id = studentService.add(student);
            return ResultResponse.success(id.toString());
        }catch (Exception e){
            return ResultResponse.error(e.getMessage());
        }
    }

    @GetMapping("/get/{id}")
    public ResultResponse get(@PathVariable("id")Long id,@RequestParam Integer db){
        try {
            Student student = studentService.get(id,db);
            return ResultResponse.success(student);
        }catch (Exception e){
            return ResultResponse.error(e.getMessage());
        }
    }

}
